﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace ModelLayer
{
    [DataContract]
    public class Route
    {
        public Route()
        {
            PartRoutes = new List<PartRoute>();
        }

        [DataMember]
        public long Id
        {
            get;
            set;
        }

        [DataMember]
        public TimeSpan TotalTime
        {
            get
            {
                TimeSpan totalTime = new TimeSpan();
                if (PartRoutes.Any())
                {
                    foreach (var partRoute in PartRoutes)
                    {
                        totalTime = totalTime.Add(partRoute.Time);
                    }
                }
                return totalTime;
            }
            set { }
        }

        [DataMember]
        public double TotalDistance
        {
            get
            {
                double totalDist = 0;
                if (PartRoutes.Any())
                {
                    foreach (var partRoute in PartRoutes)
                    {
                        totalDist += partRoute.Distance;
                    }
                }
                return totalDist;
            }
            set { }
        }

        [DataMember]
        public Station StartStation
        {
            get;
            set;
        }

        [DataMember]
        public Station EndStation
        {
            get;
            set;
        }

        [DataMember]
        public List<PartRoute> PartRoutes
        {
            get;
            set;
        }
    }
}